﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;

namespace DataAccess.Classes
{
    public class ThuongHieu
    {
        #region Anh xa cac cot trong bang => thuoc tinh
        private string _MaThuongHieu;
        public string MaThuongHieu
        {
            get { return _MaThuongHieu; }
            set { _MaThuongHieu = value; }
        }

        private string _TenThuongHieu;
        public string TenThuongHieu
        {
            get { return _TenThuongHieu; }
            set { _TenThuongHieu = value; }
        }
        #endregion
        #region Ham
        public static List<ThuongHieu> All()
        {
            return CBO.FillCollection<ThuongHieu>(DataProvider.Instance.ExecuteReader("ThuongHieu_All"));
        }

        public static ThuongHieu Single(string maHangHoa)
        {
            try
            {
                return CBO.FillObject<ThuongHieu>(DataProvider.Instance.ExecuteReader("ThuongHieu_ChonMa", maHangHoa));
            }
            catch (Exception) { return null; }
        }

        public static bool Delete(string maHangHoa)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("ThuongHieu_Xoa", maHangHoa);
                return rs > 0;
            }
            catch
            {
                return false;
            }             
        }
        public static bool Update(ThuongHieu data) 
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("ThuongHieu_Sua", data.MaThuongHieu, data.TenThuongHieu);
                return rs > 0;
            }
            catch
            {
                return false; 
            }
        }
        public static bool Add(ThuongHieu data) 
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("ThuongHieu_Them", data.MaThuongHieu, data.TenThuongHieu);
                return rs > 0;
            }
            catch
            {
                return false; 
            }          
        }
        #endregion
    }
}
